package com.woyou.utils;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;

import com.woyou.ui.activity.LoginActivity_;

public class Dialog {
	AlertDialog dialog;

	public void Toast(final Context con, String message) {

		Builder b = new AlertDialog.Builder(con);
		b.setTitle("提示");
		b.setMessage(message);// 设置信息
		b.setCancelable(true);

		b.setPositiveButton("确定", new DialogInterface.OnClickListener() {// 设置监听事件
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
					}
				});
		try {
			if (dialog == null || !dialog.isShowing()) {
				dialog = b.create();// 创建对话框
				dialog.show();// 显示对话框
				dialog.setCanceledOnTouchOutside(false);// 设置点击Dialog外部任意区域关
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void LoginToast(final Context mContext, String msg) {
		Builder b = new AlertDialog.Builder(mContext);
		b.setTitle("提示：");
		b.setMessage(msg);// 设置信息
		b.setCancelable(false);

		b.setPositiveButton("知道了", new DialogInterface.OnClickListener() {// 设置监听事件
					public void onClick(DialogInterface dialog, int which) {
						Utils.openActivity(mContext, LoginActivity_.class, null);
						dialog.dismiss();
					}
				});
		try {
			if (dialog == null || !dialog.isShowing()) {
				dialog = b.create();// 创建对话框
				dialog.show();// 显示对话框
				dialog.setCanceledOnTouchOutside(false);// 设置点击Dialog外部任意区域关
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@SuppressWarnings("rawtypes")
	public void LoginToast(final Context mContext, String msg, final Class mClazz) {
		Builder b = new AlertDialog.Builder(mContext);
		b.setTitle("提示：");
		b.setMessage(msg); // 设置信息
		b.setCancelable(false);

		b.setPositiveButton("知道了", new DialogInterface.OnClickListener() {// 设置监听事件
					public void onClick(DialogInterface dialog, int which) {
						Utils.openActivity(mContext, LoginActivity_.class, null);
						dialog.dismiss();
					}
				});
		try {
			if (dialog == null || !dialog.isShowing()) {
				dialog = b.create();// 创建对话框
				dialog.show();// 显示对话框
				dialog.setCanceledOnTouchOutside(false);// 设置点击Dialog外部任意区域关
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void dismiss() {
		if (dialog != null && dialog.isShowing()) {
			dialog.dismiss();
		}
	}

}
